home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / helper / source / graphic.c < prev    next >
Text File  |  1991-10-18  |  25KB  |  1,065 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <stdarg.h>
  4. #include    <string.h>
  5. #include    <egb.h>
  6. #include    <mos.h>
  7. #include    <snd.h>
  8. #include    <msdos.cf>
  9. #include    "graphic.h"
  10. #include    "coldef.h"
  11.  
  12. #define    TRUE    1
  13. #define    FALSE    0
  14. #define    ERR    (-1)
  15.  
  16. int    tick_timer=0;
  17. int    now_mos=0;
  18. char    work[EgbWorkSize];
  19. char    mwork[MosWorkSize];
  20. char    swork[16384];
  21.  
  22. static char    *timer_addr=NULL;
  23. static struct _PLT {
  24.     char    b,r,g;
  25.     } plt_tbl[16]={
  26.     { 0x00,0x00,0x00 },{ 0x50,0xC0,0x40 },
  27.     { 0x40,0xC0,0x40 },{ 0x60,0x60,0x70 },
  28.     { 0x90,0x80,0x90 },{ 0x70,0x80,0x80 },
  29.     { 0x60,0x60,0x60 },{ 0xC0,0xC0,0xC0 },
  30.     { 0xD0,0xE0,0xD0 },{ 0x60,0x60,0x60 },
  31.     { 0x40,0xF0,0x40 },{ 0x70,0x70,0x90 },
  32.     { 0xA0,0x90,0xA0 },{ 0x90,0xA0,0xA0 },
  33.     { 0xB0,0xB0,0xB0 },{ 0xF0,0xF0,0xF0 }
  34.     };
  35.  
  36. static char    mosptn[][66]={
  37.     { 2, 16,
  38.     0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x60, 0x00, 
  39.     0x30, 0x00, 0x58, 0x00, 0x3C, 0x00, 0x5E, 0x00, 
  40.     0x2F, 0x00, 0x5F, 0x80, 0x2E, 0x00, 0x7C, 0x00, 
  41.     0x66, 0x00, 0x06, 0x00, 0x03, 0x00, 0x00, 0x00, 
  42.     0x7F, 0xFF, 0x3F, 0xFF, 0x5F, 0xFF, 0x6F, 0xFF, 
  43.     0x37, 0xFF, 0x5B, 0xFF, 0x3D, 0xFF, 0x5E, 0xFF, 
  44.     0x2F, 0x7F, 0x5F, 0xBF, 0x2E, 0x7F, 0x7D, 0xFF, 
  45.     0x66, 0xFF, 0x16, 0xFF, 0x7B, 0x7F, 0xF8, 0x7F },
  46.     { 2, 16,
  47.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x40, 
  48.     0x05, 0x40, 0x05, 0x50, 0x15, 0x50, 0x15, 0x50, 
  49.     0x1F, 0xF0, 0x1F, 0xF0, 0x1F, 0xF0, 0x0F, 0xF0, 
  50.     0x07, 0xE0, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00,
  51.     0xFF, 0xFF, 0xFF, 0xFF, 0xFA, 0xBF, 0xF5, 0x5F, 
  52.     0xF5, 0x4F, 0xE5, 0x57, 0xD5, 0x57, 0xD5, 0x57, 
  53.     0xDF, 0xF7, 0xDF, 0xF7, 0xDF, 0xF7, 0xEF, 0xF7, 
  54.     0xF7, 0xEF, 0xFB, 0xDF, 0xFF, 0xFF, 0xFF, 0xFF },
  55.     { 2, 16,
  56.     0x00, 0x00, 0x2F, 0xF4, 0x2F, 0xF4, 0x2F, 0xF4, 
  57.     0x37, 0xEC, 0x39, 0x9C, 0x3C, 0x3C, 0x3E, 0x7C, 
  58.     0x3E, 0x7C, 0x3D, 0xBC, 0x3B, 0xDC, 0x36, 0x6C, 
  59.     0x2C, 0x34, 0x28, 0x14, 0x20, 0x04, 0x00, 0x00,
  60.     0x00, 0x00, 0xAF, 0xF5, 0xAF, 0xF5, 0xAF, 0xF5, 
  61.     0xB7, 0xED, 0xB9, 0x9D, 0xBC, 0x3D, 0xBE, 0x7D, 
  62.     0xBE, 0x7D, 0xBD, 0xBD, 0xBB, 0xDD, 0xB6, 0x6D, 
  63.     0xAC, 0x35, 0xA8, 0x15, 0xA0, 0x05, 0x00, 0x00 },
  64.     { 2, 16,
  65.     0x03, 0x00, 0x03, 0x80, 0x02, 0xC0, 0x02, 0x40, 
  66.     0x02, 0x40, 0x02, 0x00, 0x0E, 0x00, 0x1E, 0x00, 
  67.     0x1E, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x6A, 0xE0, 
  68.     0x4A, 0xA0, 0x6A, 0xE0, 0x4A, 0x80, 0x6E, 0x80,
  69.     0xFB, 0x7F, 0xFB, 0xBF, 0xFA, 0xDF, 0xFA, 0x5F, 
  70.     0xFA, 0x5F, 0xE2, 0x9F, 0xCE, 0xFF, 0xDE, 0xFF, 
  71.     0xDE, 0xFF, 0xCD, 0xFF, 0xE1, 0xFF, 0xFF, 0xFF, 
  72.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
  73.     { 2, 16,
  74.     0x00, 0x00, 0x07, 0x00, 0x08, 0x80, 0x0A, 0x40, 
  75.     0x01, 0x40, 0x05, 0x40, 0x02, 0x40, 0x08, 0x40, 
  76.     0x04, 0x80, 0x07, 0x00, 0x00, 0x00, 0x75, 0x60, 
  77.     0x47, 0x50, 0x77, 0x50, 0x17, 0x50, 0x75, 0x60,
  78.     0xF0, 0x7F, 0xF7, 0x7F, 0xE8, 0xBF, 0xEA, 0x5F, 
  79.     0xE1, 0x5F, 0xE5, 0x5F, 0xE2, 0x5F, 0xE8, 0x5F, 
  80.     0xF4, 0xBF, 0xF7, 0x7F, 0xF0, 0x7F, 0xFF, 0xFF, 
  81.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } };
  82.  
  83. void    DSP_mos(int no)
  84. {
  85.     now_mos = no;
  86.     MOS_type(1,0,0,mosptn[no]);
  87. }
  88. BLOCK    *DSP_push_vram(int x1,int y1,int x2,int y2)
  89. {
  90.     register BLOCK *para;
  91.     int     n;
  92.  
  93.     n = ((x2 - x1 + 8) / 8 * 4) * (y2 - y1 + 1) + 16;    /* 4 Bit Pix */
  94.  
  95.     if ( (para = (BLOCK *)malloc(n)) == NULL )
  96.     return NULL;
  97.  
  98.     para->ptn = para->img;
  99.     para->sel = getds();
  100.     para->x1 = x1;
  101.     para->y1 = y1;
  102.     para->x2 = x2;
  103.     para->y2 = y2;
  104.     EGB_getBlock(work,(char *)para);
  105.     return para;
  106. }
  107. void    DSP_pop_vram(BLOCK *para)
  108. {
  109.     if ( para == NULL )
  110.     return;
  111.     EGB_putBlock(work,0,(char *)para);
  112.     free(para);
  113. }
  114. void    DSP_putptn(char *ptn,int x1,int y1,int x2,int y2,
  115.             int fc,int bc,int md)
  116. {
  117.     BLOCK para;
  118.  
  119.     para.ptn = ptn;
  120.     para.sel = getds();
  121.     para.x1 = x1;
  122.     para.y1 = y1;
  123.     para.x2 = x2;
  124.     para.y2 = y2;
  125.     EGB_color(work,0,fc);
  126.     EGB_color(work,1,bc);
  127.     EGB_writeMode(work,md);
  128.     EGB_putBlockColor(work,0,(char *)(¶));
  129.     EGB_writeMode(work,0);
  130. }
  131. void    DSP_msg(char *str,int x,int y,int font,int fc,int bc,int mod)
  132. {
  133.     struct {
  134.     short int    x,y;
  135.     short int    len;
  136.     char        str[120];
  137.     } msg;
  138.  
  139.     msg.x = x;
  140.     msg.y = y + 15;
  141.     msg.len = strlen(str);
  142.     strcpy(msg.str,str);
  143.  
  144.     EGB_textSpace(work,0);
  145.     EGB_fontStyle(work,font);
  146.     EGB_color(work,0,fc);
  147.     EGB_color(work,1,bc);
  148.     EGB_writeMode(work,mod);
  149.     EGB_sjisString(work,(char *)&msg);
  150. }
  151. void    DSP_line(int x1,int y1,int x2,int y2,int col,int mod)
  152. {
  153.     struct {
  154.     short int    x1,y1,x2,y2;
  155.     } line;
  156.  
  157.     line.x1 = x1;
  158.     line.y1 = y1;
  159.     line.x2 = x2;
  160.     line.y2 = y2;
  161.     EGB_paintMode(work,0x002);
  162.     EGB_color(work,0,col);
  163.     EGB_writeMode(work,mod);
  164.     EGB_rectangle(work,(char *)&line);
  165.     EGB_writeMode(work,0);
  166. }
  167. void    DSP_box(int x1,int y1,int x2,int y2,int col,int mod)
  168. {
  169.     struct {
  170.     short int    x1,y1,x2,y2;
  171.     } line;
  172.  
  173.     line.x1 = x1;
  174.     line.y1 = y1;
  175.     line.x2 = x2;
  176.     line.y2 = y2;
  177.     EGB_paintMode(work,0x022);
  178.     EGB_color(work,0,col);
  179.     EGB_color(work,2,col);
  180.     EGB_writeMode(work,mod);
  181.     EGB_rectangle(work,(char *)&line);
  182.     EGB_writeMode(work,0);
  183. }
  184. void    DSP_rbox(int x1,int y1,int x2,int y2,int lin,int col,int mod)
  185. {
  186.     struct {
  187.     short int    x1,y1,x2,y2;
  188.     } line;
  189.  
  190.     line.x1 = x1;
  191.     line.y1 = y1;
  192.     line.x2 = x2;
  193.     line.y2 = y2;
  194.     EGB_paintMode(work,0x022);
  195.     EGB_color(work,0,lin);
  196.     EGB_color(work,2,col);
  197.     EGB_writeMode(work,mod);
  198.     EGB_rectangle(work,(char *)&line);
  199.     EGB_writeMode(work,0);
  200. }
  201. void    DSP_wbox(int x1,int y1,int x2,int y2,int lin,int col,int mod)
  202. {
  203.     struct {
  204.     short int    point;
  205.     short int    trx2,try2;
  206.     short int    trx3,try3;
  207.     short int    brx1,bry1;
  208.     short int    brx2,bry2;
  209.     short int    brx3,bry3;
  210.     short int    blx1,bly1;
  211.     short int    blx2,bly2;
  212.     short int    blx3,bly3;
  213.     short int    tlx1,tly1;
  214.     short int    tlx2,tly2;
  215.     short int    tlx3,tly3;
  216.     short int    trx1,try1;
  217.     } poly;
  218.  
  219.     poly.point = 12;
  220.  
  221.     poly.tlx1 = x1+0; poly.tlx2 = x1+1; poly.tlx3 = x1+2;
  222.     poly.tly1 = y1+2; poly.tly2 = y1+1; poly.tly3 = y1+0;
  223.  
  224.     poly.trx1 = x2-2; poly.trx2 = x2-1; poly.trx3 = x2+0;
  225.     poly.try1 = y1+0; poly.try2 = y1+1; poly.try3 = y1+2;
  226.  
  227.     poly.brx1 = x2+0; poly.brx2 = x2-1; poly.brx3 = x2-2;
  228.     poly.bry1 = y2-2; poly.bry2 = y2-1; poly.bry3 = y2+0;
  229.  
  230.     poly.blx1 = x1+2; poly.blx2 = x1+1; poly.blx3 = x1+0;
  231.     poly.bly1 = y2-0; poly.bly2 = y2-1; poly.bly3 = y2-2;
  232.  
  233.     EGB_paintMode(work,0x022);
  234.     EGB_color(work,0,lin);
  235.     EGB_color(work,2,col);
  236.     EGB_writeMode(work,mod);
  237.     EGB_polygon(work,(char *)&poly);
  238.  
  239.     poly.point = 7;
  240.     EGB_paintMode(work,0x002);
  241.     EGB_color(work,0,lin ^ 0x08);
  242.     EGB_connect(work,(char *)&poly);
  243.  
  244.     EGB_writeMode(work,0);
  245. }
  246. void    DSP_vsync(void)
  247. {
  248.     while ( (peek(0xFDA0) & 1) != 0 );
  249.     while ( (peek(0xFDA0) & 1) == 0 );
  250. }
  251. void    DSP_opbox(int x1,int y1,int x2,int y2)
  252. {
  253.     int     i;
  254.     int     ix1,iy1,ix2,iy2;
  255.     int     sx1,sy1,sx2,sy2;
  256.  
  257.     ix1 = (x1 + x2) / 2 - 8;
  258.     ix2 = ix1 + 15;
  259.     iy1 = (y1 + y2) / 2 - 8;
  260.     iy2 = iy1 + 15;
  261.  
  262.     sx1 = (ix1 - x1) / 10;
  263.     sy1 = (iy1 - y1) / 10;
  264.     sx2 = (x2 - ix2) / 10;
  265.     sy2 = (y2 - iy2) / 10;
  266.  
  267.     for ( i = 10 ; i >= 0 ; i-- ) {
  268.     DSP_line(ix1,iy1,ix2,iy2,15,4);
  269.     DSP_vsync();
  270.     DSP_line(ix1,iy1,ix2,iy2,15,4);
  271.     ix1 -= sx1;
  272.     iy1 -= sy1;
  273.     ix2 += sx2;
  274.     iy2 += sy2;
  275.     }
  276. }
  277. void    DSP_clbox(int x1,int y1,int x2,int y2)
  278. {
  279.     int     i;
  280.     int     ix1,iy1,ix2,iy2;
  281.     int     sx1,sy1,sx2,sy2;
  282.  
  283.     ix1 = (x1 + x2) / 2 - 8;
  284.     ix2 = ix1 + 15;
  285.     iy1 = (y1 + y2) / 2 - 8;
  286.     iy2 = iy1 + 15;
  287.  
  288.     sx1 = (ix1 - x1) / 10;
  289.     sy1 = (iy1 - y1) / 10;
  290.     sx2 = (x2 - ix2) / 10;
  291.     sy2 = (y2 - iy2) / 10;
  292.  
  293.     for ( i = 10 ; i >= 0 ; i-- ) {
  294.     DSP_line(x1,y1,x2,y2,15,4);
  295.     DSP_vsync();
  296.     DSP_line(x1,y1,x2,y2,15,4);
  297.     x1 += sx1;
  298.     y1 += sy1;
  299.     x2 -= sx2;
  300.     y2 -= sy2;
  301.     }
  302. }
  303. void    TICK_count(void)
  304. {
  305.     tick_timer++;
  306.     SND_fm_timer_a_start();
  307. }
  308. void    DSP_palette(void)
  309. {
  310.     struct {
  311.     int    cnt;
  312.     int    col;
  313.     char    b,r,g;
  314.     char    btm;
  315.     } para;
  316.     int     i;
  317.  
  318.     for ( i = 0 ; i < 16 ; i++ ) {
  319.     para.cnt = 1;
  320.     para.col = i;
  321.     para.b = plt_tbl[i].b;
  322.     para.r = plt_tbl[i].r;
  323.     para.g = plt_tbl[i].g;
  324.     para.btm = 0;
  325.         EGB_palette(work,0,(char *)¶);
  326.     }
  327. }
  328.  
  329. #define HSW1    0
  330. #define HSW2    1
  331. #define HST     4
  332. #define CR1     29
  333. #define HDS0    9
  334. #define HDE0    10
  335. #define HDS1    11
  336. #define HDE1    11
  337. #define HAJ0    18
  338. #define HAJ1    22
  339.  
  340. #define    CRTC(r,n)    vram_offset(r,n)
  341.  
  342. void    DSP_init(void)
  343. {
  344.     SND_init(swork);
  345.     SND_elevol_mute(0xB3);
  346.  
  347.     timer_addr = SND_int_timer_a_get();
  348.     SND_int_timer_a_set((char *)TICK_count);
  349.     SND_fm_timer_a_set(1,900);
  350.  
  351.     EGB_init(work,EgbWorkSize);
  352.     EGB_resolution(work,0,3);
  353.     EGB_resolution(work,1,3);
  354.     EGB_displayPage(work,0,3);
  355.     EGB_writePage(work,1);
  356.     DSP_palette();
  357.     EGB_writePage(work,0);
  358.     DSP_palette();
  359.  
  360.     MOS_start(mwork,MosWorkSize);
  361.     MOS_resolution(0,3);
  362.     MOS_resolution(1,3);
  363.     MOS_writePage(0);
  364.     MOS_horizon(0,632);
  365.     MOS_vertical(0,470);
  366.     DSP_mos(MOS_NOMAL);
  367.     MOS_disp(TRUE);
  368.     ctblset(15,SCRN_COL);
  369. }
  370. void    DSP_end(void)
  371. {
  372.     SND_fm_timer_a_set(0,900);
  373.     SND_int_timer_a_set(timer_addr);
  374.     MOS_end();
  375.     SND_elevol_mute(0x00);
  376.     SND_end();
  377. }
  378. void    gprintf(int x,int y,int c,int b,char *form,...)
  379. {
  380.     va_list arg;
  381.     char    tmp[256];
  382.  
  383.     va_start(arg,form);
  384.     vsprintf((char *)tmp,form,arg);
  385.     wrtstr(tmp,0,x,y,c,b,16);
  386.     va_end(arg);
  387. }
  388. void    gputs(int x,int y,int c,int b,char *str)
  389. {
  390.     wrtstr(str,0,x,y,c,b,16);
  391. }
  392. void    DSP_offset(int page,int x,int y)
  393. {
  394.     vram_offset((page == 0 ? 17:21),x/8+y*128);
  395. }
  396. void    DSP_clear(int no)
  397. {
  398.     EGB_writePage(work,no);
  399.     EGB_color(work,1,0);
  400.     EGB_clearScreen(work);
  401.     EGB_writePage(work,0);
  402. }
  403. void    DSP_page(int no)
  404. {
  405.     EGB_writePage(work,no);
  406. }
  407. #include    "sysicon.c"
  408.  
  409. int    ESR_setupInfo(char *out_buf);
  410.  
  411. char    drv_tbl[]={
  412.     IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,
  413.     IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,
  414.     IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON,IS_NON };
  415.  
  416. void    ICON_init(void)
  417. {
  418.     int     i;
  419.     char    tmp[256];
  420.  
  421.     ESR_setupInfo((char *)tmp);
  422.     for ( i = 0 ; i < 16 ; i++ )
  423.     drv_tbl[i] = tmp[0x30 + i * 2];
  424.     drv_tbl[2] = IS_NON;            /* C: drive delete */
  425.     drv_tbl[16] = IS_CDR;            /* Q: drive apend */
  426. }
  427. void    ICON_disp(int x,int y,int drv)
  428. {
  429.     DSP_rbox(x,y,x+33,y+33,LINE_COL,WIND_COL,M_PSET);
  430.     if ( drv_tbl[drv] <= IS_CDR )
  431.     DSP_putptn(ICON_ptn[drv_tbl[drv]],x+1,y+1,x+32,y+32,
  432.                 CHR_COL,WIND_COL,M_PSET);
  433.     else
  434.     gprintf(x+12,y+12,CHR_COL,WIND_COL,"%d",drv_tbl[drv]);
  435.     DSP_box(x+2,y+2,x+15,y+14,WIND_COL,M_PSET);
  436.     DSP_putptn(DIGIT_ptn[drv],x+2,y+2,x+15,y+14,CHR_COL,WIND_COL,M_PSET);
  437. }
  438.  
  439. /********************************************************************
  440.  
  441.     Palette Control
  442.  
  443.     0      1        2          3        4      5
  444.     0123456789012345678901234567890123456789012345678901234567890
  445. 0    ■  < 00 >  < 00 >  < 00 >    ■  < 00 >  < 00 >  < 00 >
  446. 1    ■  < 00 >  < 00 >  < 00 >    ■  < 00 >  < 00 >  < 00 >
  447. 2    ■  < 00 >  < 00 >  < 00 >    ■  < 00 >  < 00 >  < 00 >
  448. 3    ■  < 00 >  < 00 >  < 00 >    ■  < 00 >  < 00 >  < 00 >
  449. 4    ■  < 00 >  < 00 >  < 00 >    ■  < 00 >  < 00 >  < 00 >
  450. 5    ■  < 00 >  < 00 >  < 00 >    ■  < 00 >  < 00 >  < 00 >
  451. 6    ■  < 00 >  < 00 >  < 00 >    ■  < 00 >  < 00 >  < 00 >
  452. 7    ■  < 00 >  < 00 >  < 00 >    ■  < 00 >  < 00 >  < 00 >
  453.  
  454. ********************************************************************/
  455.  
  456. #define    PLT_X    80
  457. #define    PLT_Y    140
  458.  
  459. #define    PLT_X1    PLT_X-8
  460. #define    PLT_Y1    PLT_Y-40
  461. #define    PLT_X2    PLT_X+480
  462. #define    PLT_Y2    PLT_Y+192
  463.  
  464. void    PLT_node(int col)
  465. {
  466.     int     x,y;
  467.     struct {
  468.     int    cnt;
  469.     int    col;
  470.     char    b,r,g;
  471.     char    btm;
  472.     } para;
  473.     
  474.     MOS_disp(0);
  475.  
  476.     x = PLT_X + (col / 8) * 256;
  477.     y = PLT_Y + (col % 8) * 22;
  478.  
  479.     DSP_wbox(x,y,x+19,y+19,LINE_COL,col,M_PSET);
  480.  
  481.     DSP_wbox(x+32,y,x+32+11,y+19,LINE_COL,WIND_COL,M_PSET);
  482.     gputs(x+32+2,y+2,CHR_COL,WIND_COL,"<");
  483.     DSP_wbox(x+72,y,x+72+11,y+19,LINE_COL,WIND_COL,M_PSET);
  484.     gputs(x+72+2,y+2,CHR_COL,WIND_COL,">");
  485.  
  486.     DSP_wbox(x+96,y,x+96+11,y+19,LINE_COL,WIND_COL,M_PSET);
  487.     gputs(x+96+2,y+2,CHR_COL,WIND_COL,"<");
  488.     DSP_wbox(x+136,y,x+136+11,y+19,LINE_COL,WIND_COL,M_PSET);
  489.     gputs(x+136+2,y+2,CHR_COL,WIND_COL,">");
  490.  
  491.     DSP_wbox(x+160,y,x+160+11,y+19,LINE_COL,WIND_COL,M_PSET);
  492.     gputs(x+160+2,y+2,CHR_COL,WIND_COL,"<");
  493.     DSP_wbox(x+200,y,x+200+11,y+19,LINE_COL,WIND_COL,M_PSET);
  494.     gputs(x+200+2,y+2,CHR_COL,WIND_COL,">");
  495.  
  496.     gprintf(x+48+2,y+2,CHR_COL,WIND_COL,"%02d",plt_tbl[col].b/16);
  497.     gprintf(x+112+2,y+2,CHR_COL,WIND_COL,"%02d",plt_tbl[col].r/16);
  498.     gprintf(x+176+2,y+2,CHR_COL,WIND_COL,"%02d",plt_tbl[col].g/16);
  499.  
  500.     para.cnt = 1;
  501.     para.col = col;
  502.     para.b = plt_tbl[col].b;
  503.     para.r = plt_tbl[col].r;
  504.     para.g = plt_tbl[col].g;
  505.     para.btm = 0;
  506.     EGB_palette(work,0,(char *)¶);
  507.  
  508.     MOS_disp(1);
  509. }
  510. void    PLT_chk(int mx,int my,int col)
  511. {
  512.     int     x,y;
  513.  
  514.     x = PLT_X + (col / 8) * 256;
  515.     y = PLT_Y + (col % 8) * 22;
  516.  
  517.     if      ( (mx >= (x+32)) && (my >= y) && 
  518.           (mx <= (x+32+11)) && (my <= (y+19)) )
  519.     plt_tbl[col].b = (plt_tbl[col].b - 0x10) & 0xF0;
  520.  
  521.     else if ( (mx >= (x+72)) && (my >= y) && 
  522.           (mx <= (x+72+11)) && (my <= (y+19)) )
  523.     plt_tbl[col].b = (plt_tbl[col].b + 0x10) & 0xF0;
  524.  
  525.     else if ( (mx >= (x+96)) && (my >= y) && 
  526.           (mx <= (x+96+11)) && (my <= (y+19)) )
  527.     plt_tbl[col].r = (plt_tbl[col].r - 0x10) & 0xF0;
  528.  
  529.     else if ( (mx >= (x+136)) && (my >= y) && 
  530.           (mx <= (x+136+11)) && (my <= (y+19)) )
  531.     plt_tbl[col].r = (plt_tbl[col].r + 0x10) & 0xF0;
  532.  
  533.     else if ( (mx >= (x+160)) && (my >= y) && 
  534.           (mx <= (x+160+11)) && (my <= (y+19)) )
  535.     plt_tbl[col].g = (plt_tbl[col].g - 0x10) & 0xF0;
  536.  
  537.     else if ( (mx >= (x+200)) && (my >= y) && 
  538.           (mx <= (x+200+11)) && (my <= (y+19)) )
  539.     plt_tbl[col].g = (plt_tbl[col].g + 0x10) & 0xF0;
  540.  
  541.     else
  542.     return;
  543.  
  544.     PLT_node(col);
  545. }
  546. void    PLT_control(void)
  547. {
  548.     int     n,i;
  549.     int     x,y,sw;
  550.     BLOCK   *vp;
  551.  
  552.     MOS_disp(0);
  553.     vp = DSP_push_vram(PLT_X1,PLT_Y1,PLT_X2,PLT_Y2);
  554.     DSP_opbox(PLT_X1,PLT_Y1,PLT_X2,PLT_Y2);
  555. /****
  556.     DSP_wbox(PLT_X1,PLT_Y1,PLT_X2,PLT_Y2,LINE_COL,WIND_COL,M_PSET);
  557. *****/
  558.     DSP_wbox(PLT_X1+8,PLT_Y1+8,PLT_X1+38,PLT_Y1+27,LINE_COL,WIND_COL,M_PSET);
  559.     gputs(PLT_X1+10,PLT_Y1+10,CHR_COL,WIND_COL,"END");
  560.     MOS_disp(1);
  561.  
  562.     for ( i = 0 ; i < 16 ; i++ )
  563.     PLT_node(i);
  564.  
  565.     for ( ; ; ) {
  566.     MOS_rdpos(&sw,&x,&y);
  567.  
  568.     if ( (sw == 0)    ||
  569.          (x < PLT_X1) || (y < PLT_Y1) ||
  570.          (x > PLT_X2) || (y > PLT_Y2) )
  571.         continue;
  572.  
  573.     else if ( (x >= (PLT_X1+8))  && (y >= (PLT_Y1+8)) &&
  574.               (x <= (PLT_X1+38)) && (y <= (PLT_Y1+27)) )
  575.         break;
  576.  
  577.     else {
  578.         for ( i = 0 ; i < 16 ; i++ )
  579.             PLT_chk(x,y,i);
  580.     }
  581.  
  582.     do {
  583.         MOS_rdpos(&sw,&x,&y);
  584.     } while ( sw != 0 );
  585.     }
  586.  
  587.     MOS_disp(0);
  588.     DSP_pop_vram(vp);
  589.     MOS_disp(1);
  590. }
  591.  
  592. /****************************************************
  593.  
  594.     TIFF Graphic Display and SND or EUP Play
  595.  
  596. *****************************************************/
  597. char    *getins(env,file)
  598. char    *env,*file;
  599. {
  600.     static char tmp[128];
  601.     char *p;
  602.  
  603.     if ( (p = getenv(env)) == NULL )
  604.     return NULL;
  605.     sprintf(tmp,"%s\\%s",p,file);
  606.     return tmp;
  607. }
  608. char    *xopen(char *file)
  609. {
  610.     FILE    *fp;
  611.     long    fsz;
  612.     char    *buf;
  613.  
  614.     if( (fp = fopen(file,"rb")) == NULL )
  615.     return NULL;
  616.  
  617.     fseek(fp,0L,SEEK_END);
  618.     fsz = ftell(fp);
  619.     rewind(fp);
  620.  
  621.     if( (buf = (char *)malloc(fsz)) == NULL)
  622.     goto ERROR;
  623.  
  624.     fread(buf,fsz,1,fp);
  625.  
  626. ERROR:
  627.     fclose(fp);
  628.     return buf;
  629. }
  630. void    xclose(char *buf)
  631. {
  632.     free(buf);
  633. }
  634. void    DSP_tiff(char *file)
  635. {
  636.     int        l,n;
  637.     int     sw,x,y;
  638.     int     len,lzw,plt;
  639.     BLOCK   para;
  640.     BLOCK   *save;
  641.     char    *buf;
  642.     short   *rp,*gp,*bp;
  643.     struct _TIF {
  644.     short    tf_tag;
  645.     short    tf_type;
  646.     int    tf_len;
  647.     int    tf_data;
  648.     } *ifd;
  649.     struct {
  650.     int    cnt;
  651.     int    col;
  652.     char    b,r,g;
  653.     char    btm;
  654.     } plpara;
  655.  
  656.     if ( (buf = xopen(file)) == NULL ) {
  657.     kakunin("TIFFファイルの読み込みに失敗しました");
  658.     return;
  659.     }
  660.  
  661.     if ( buf[0] != 0x49 || buf[1] != 0x49 || buf[2] != 0x2A ) {
  662.     kakunin("このファイルはTIFF形式ではありません?");
  663.     goto ENDOF;
  664.     }
  665.  
  666.     x = y = len = plt = 0;
  667.     lzw = 1;
  668.     n = WORD(buf + DWORD(buf+4));
  669.     ifd = (struct _TIF *)(buf + DWORD(buf+4) + 2);
  670.  
  671.     while ( n-- > 0) {
  672.     if ( ifd->tf_tag == 0 )
  673.         break;
  674.     switch(ifd->tf_tag){
  675.     case 0x0100: x = ifd->tf_data; break;
  676.     case 0x0101: y = ifd->tf_data; break;
  677.     case 0x0102: len = ifd->tf_data; break;
  678.     case 0x0103: lzw = ifd->tf_data; break;
  679.     case 0x0140: plt = ifd->tf_data; break;
  680.     case 0x0111: l = ifd->tf_data; break;
  681.     }
  682.     ifd++;
  683.     }
  684.  
  685.     if ( lzw != 1 ) {
  686.     kakunin("残念ながら圧縮TIFFに対応してません");
  687.     goto ENDOF;
  688.     }
  689.     if ( len != 1 && len != 4 && len != 8 && len != 16 ) {
  690.     kakunin("対応していないピクセルモ-ドです");
  691.     goto ENDOF;
  692.     }
  693.  
  694.     para.ptn = buf + l;
  695.     para.sel = getds();
  696.     para.x1 = 0;
  697.     para.y1 = 0;
  698.     para.x2 = x-1;
  699.     para.y2 = y-1;
  700.  
  701.     MOS_disp(OFF);
  702.     save = DSP_push_vram(0,0,639,479);
  703.     EGB_displayPage(work,0,0);
  704.  
  705.     switch(len) {
  706.     case 1:
  707.         EGB_resolution(work,0,3);
  708.     EGB_writePage(work,0);
  709.     EGB_clearScreen(work);
  710.     EGB_color(work,0,15);
  711.     EGB_putBlockColor(work,0,(char *)¶);
  712.     break;
  713.  
  714.     case 4:
  715.         EGB_resolution(work,0,3);
  716.     EGB_writePage(work,0);
  717.     EGB_clearScreen(work);
  718.     EGB_putBlock(work,0,(char *)¶);
  719.     if ( plt != 0 ) {
  720.         rp = (short *)(buf + plt);
  721.         gp = (short *)(buf + plt + 32);
  722.         bp = (short *)(buf + plt + 64);
  723.         for ( n = 0 ; n < 16 ; n++ ) {
  724.         plpara.cnt = 1;
  725.         plpara.col = n;
  726.         plpara.b = *(bp++);
  727.         plpara.r = *(rp++);
  728.         plpara.g = *(bp++);
  729.         plpara.btm = 0;
  730.         EGB_palette(work,0,(char *)&plpara);
  731.         }
  732.     }
  733.     break;
  734.  
  735.     case 8:
  736.     EGB_resolution(work,0,12);
  737.     EGB_clearScreen(work);
  738.     EGB_putBlock(work,0,(char *)¶);
  739.     if ( plt != 0 ) {
  740.         rp = (short *)(buf + plt);
  741.         gp = (short *)(buf + plt + 512);
  742.         bp = (short *)(buf + plt + 1024);
  743.         for ( n = 0 ; n < 256 ; n++ ) {
  744.         plpara.cnt = 1;
  745.         plpara.col = n;
  746.         plpara.b = *(bp++);
  747.         plpara.r = *(rp++);
  748.         plpara.g = *(bp++);
  749.         plpara.btm = 0;
  750.         EGB_palette(work,0,(char *)&plpara);
  751.         }
  752.     }
  753.     break;
  754.  
  755.     case 16:
  756.         EGB_resolution(work,0,10);
  757.     EGB_writePage(work,0);
  758.     EGB_clearScreen(work);
  759.     EGB_displayStart(work,2,2,2);
  760.     EGB_displayStart(work,3,320,240);
  761.     EGB_putBlock(work,0,(char *)¶);
  762.     break;
  763.  
  764.     }
  765.  
  766.     EGB_displayPage(work,0,1);
  767.  
  768.     do {
  769.     MOS_rdpos(&sw,&x,&y);
  770.     } while ( sw == 0 );
  771.  
  772.     EGB_displayPage(work,0,0);
  773.     EGB_resolution(work,0,3);
  774.     EGB_resolution(work,1,3);
  775.     EGB_writePage(work,1);
  776.     DSP_palette();
  777.     EGB_clearScreen(work);
  778.     EGB_writePage(work,0);
  779.     DSP_palette();
  780.     EGB_clearScreen(work);
  781.     DSP_pop_vram(save);
  782.     EGB_displayPage(work,0,3);
  783.     MOS_disp(ON);
  784.  
  785. ENDOF:
  786.     xclose(buf);
  787. }
  788. void    DSP_pxx(char *file)
  789. {
  790.     int     n;
  791.     int     sw,x,y;
  792.     int     objs;
  793.     int     plat;
  794.     int     mode;
  795.     long    size;
  796.     short   *sp;
  797.     char    *data;
  798.     char    *buf;
  799.     BLOCK   para;
  800.     BLOCK   *save;
  801.     struct {
  802.     int    cnt;
  803.     int    col;
  804.     char    b,r,g;
  805.     char    btm;
  806.     } plpara;
  807.  
  808.     if ( (buf = xopen(file)) == NULL ) {
  809.     kakunin("Pxxファイルの読み込みに失敗しました");
  810.     return;
  811.     }
  812.  
  813.     if ( buf[0] != 0x59 || buf[1] != 0x55 || 
  814.      buf[2] != 0x4B || buf[3] != 0x49 ) {
  815.     kakunin("このファイルはPxx形式ではありません?");
  816.     goto ENDOF;
  817.     }
  818.  
  819.     objs = WORD(buf + 0x10);
  820.     mode = WORD(buf + 0x12);    /* 3 or 12 or 10 */
  821.     plat = (mode == 3 ? 96:(mode == 12 ? 1536:448));
  822.     data = buf + 0x18 + plat;
  823.  
  824.     if ( mode != 3 && mode != 12 && mode != 10 ) {
  825.     kakunin("対応していない画面モ-ドです");
  826.     goto ENDOF;
  827.     }
  828.  
  829.     MOS_disp(OFF);
  830.     save = DSP_push_vram(0,0,639,479);
  831.     EGB_displayPage(work,0,0);
  832.     EGB_resolution(work,0,mode);
  833.     EGB_writePage(work,0);
  834.     EGB_clearScreen(work);
  835.     if ( mode == 10 ) {
  836.     EGB_displayStart(work,2,2,2);
  837.     EGB_displayStart(work,3,320,240);
  838.     } else {
  839.     sp = (short *)(buf + 0x18);
  840.     for ( n = 0 ; n < (plat / 6) ; n++ ) {
  841.         plpara.cnt = 1;
  842.         plpara.col = n;
  843.         plpara.r = *(sp++) >> 8;
  844.         plpara.g = *(sp++) >> 8;
  845.         plpara.b = *(sp++) >> 8;
  846.         plpara.btm = 0;
  847.         EGB_palette(work,0,(char *)&plpara);
  848.     }
  849.     }
  850.  
  851.     EGB_displayPage(work,0,1);
  852.     para.sel = getds();
  853.  
  854.     while ( objs-- > 0 ) {
  855.     if ( WORD(data) == 0 ) {    /* Haikei */
  856.         size = DWORD(data + 2);
  857.         para.x1 = WORD(data + 6);
  858.         para.y1 = WORD(data + 8);
  859.         para.x2 = WORD(data + 10);
  860.         para.y2 = WORD(data + 12);
  861.         para.ptn = data + 14;
  862.         EGB_putBlock(work,0,(char *)¶);
  863.         data += (14 + size);
  864.  
  865.     } else {            /* Object */
  866.         size = DWORD(data + 2) + DWORD(data + 6);
  867.         para.x1 = WORD(data + 10);
  868.         para.y1 = WORD(data + 12);
  869.         para.x2 = WORD(data + 14);
  870.         para.y2 = WORD(data + 16);
  871.         para.ptn = data + 18;
  872.         EGB_maskData(work,2,(char *)¶);
  873.         data += (18 + size);
  874.     }
  875.  
  876.     }
  877.  
  878.     do {
  879.     MOS_rdpos(&sw,&x,&y);
  880.     } while ( sw == 0 );
  881.  
  882.     EGB_displayPage(work,0,0);
  883.     EGB_resolution(work,0,3);
  884.     EGB_resolution(work,1,3);
  885.     EGB_writePage(work,1);
  886.     DSP_palette();
  887.     EGB_clearScreen(work);
  888.     EGB_writePage(work,0);
  889.     DSP_palette();
  890.     EGB_clearScreen(work);
  891.     DSP_pop_vram(save);
  892.     EGB_displayPage(work,0,3);
  893.     MOS_disp(ON);
  894.  
  895. ENDOF:
  896.     xclose(buf);
  897. }
  898. void    PLAY_snd(file)
  899. char    *file;
  900. {
  901.     int     sw,x,y;
  902.     char    *snd_buf;
  903.  
  904.     SND_pcm_sound_delete(-1);
  905.     SND_pcm_mode_set(1);
  906.  
  907.     if ( (snd_buf = xopen(file)) == NULL ) {
  908.     kakunin("SNDファイルの読み込みに失敗しました");
  909.     return;
  910.     }
  911.  
  912.     SND_pan_set(71,64);
  913.     *(int *)(snd_buf+20) = 0;
  914.     SND_pcm_play(71,snd_buf[28],127,snd_buf);
  915.  
  916.     while ( SND_pcm_status(71) ) {
  917.     MOS_rdpos(&sw,&x,&y);
  918.     if ( sw != 0 )
  919.         break;
  920.     }
  921.  
  922.     SND_pcm_play_stop(71);
  923.     SND_pcm_rec_stop();
  924.     xclose(snd_buf);
  925. }
  926. void    PLAY_eup(file)
  927. char    *file;
  928. {
  929.     int     i;
  930.     int     sw,x,y;
  931.     int     err,size,signa,tempo;
  932.     char    *p;
  933.     char    *eup_buf;
  934.     char    tmp[16];
  935.     char    dmy[16];
  936.     char    wrk[80];
  937.  
  938.     if( (eup_buf = xopen(file)) == NULL ) {
  939.     kakunin("EUPファイルの読み込みに失敗しました");
  940.     return;
  941.     }
  942.  
  943.     SND_eup_init(swork);
  944.     SND_elevol_mute(0xB3);
  945.  
  946.     p = &eup_buf[852];        /* trk mute */
  947.     for( i = 0 ; i < 32 ; i++ )
  948.     err = SND_eup_mute_set(i,*(p++));
  949.  
  950.     p = &eup_buf[884];        /* trk port */
  951.     for( i = 0 ; i < 32 ; i++ )
  952.     err = SND_eup_port_set(i,*(p++));
  953.  
  954.     p = &eup_buf[916];        /* trk midi ch */
  955.     for( i = 0 ; i < 32 ; i++ )
  956.     err = SND_eup_midi_ch_set(i,*(p++));
  957.  
  958.     p = &eup_buf[948];        /* trk key bias */
  959.     for( i = 0 ; i < 32 ; i++ )
  960.     err = SND_eup_bias_set(i,*(p++));
  961.  
  962.     p = &eup_buf[980];        /* trk transpose */
  963.     for( i = 0 ; i < 32 ; i++ )
  964.     err = SND_eup_transpose_set(i,*(p++));
  965.  
  966. /********************
  967.     channel assign
  968. *********************/
  969.  
  970.     p = &eup_buf[1748];        /* fm midi ch */
  971.     for( i = 0 ; i < 6 ; i++ )
  972.     err = SND_midi_ch_assign(i,*(p++));
  973.  
  974.     p = &eup_buf[1754];        /* pcm midi ch */
  975.     for( i = 0 ; i < 8 ; i++ )
  976.     err = SND_midi_ch_assign(i+64,*(p++));
  977.  
  978. /****************
  979.     bank load
  980. *****************/
  981.  
  982.     SND_pcm_mode_set(0);
  983.  
  984.     strncpy(tmp,&eup_buf[1762],8);    /* fm file name */
  985.     tmp[8] = '\0';
  986.     if ( tmp[0] != '\0' ) {
  987.     strcat(tmp,".FMB");
  988.     strcpy(wrk,file);
  989.     if ( (p = strrchr(wrk,'\\')) != NULL ) {
  990.         strcpy(p+1,tmp);
  991.         p = wrk;
  992.     } else
  993.         p = tmp;
  994.     p = tmp;
  995.         if ( SND_fm_bank_load(p,dmy) != 0 ) {
  996.         if ( (p = getins("FMINST",tmp)) != NULL )
  997.          SND_fm_bank_load(p,dmy);
  998.     }
  999.     }
  1000.  
  1001.     strncpy(tmp,&eup_buf[1770],8);    /* pcm file name */
  1002.     tmp[8] = '\0';
  1003.     if ( tmp[0] != '\0' ) {
  1004.     strcat(tmp,".PMB");
  1005.     strcpy(wrk,file);
  1006.     if ( (p = strrchr(wrk,'\\')) != NULL ) {
  1007.         strcpy(p+1,tmp);
  1008.         p = wrk;
  1009.     } else
  1010.         p = tmp;
  1011.     p = tmp;
  1012.         if ( SND_pcm_bank_load(p,dmy) != 0 ) {
  1013.         if ( (p = getins("PCMINST",tmp)) != NULL )
  1014.          SND_pcm_bank_load(p,dmy);
  1015.     }
  1016.     }
  1017.  
  1018. /*******************
  1019.     play eup file
  1020. ********************/
  1021.  
  1022.     p = &eup_buf[2048];        /* data top */
  1023.     size = *((int *)p); p += 4;
  1024.     signa = *(p++);
  1025.     tempo = *(p++);
  1026.  
  1027.     SND_eup_loop_set(0);
  1028.     SND_eup_tempo_set(tempo);
  1029.     SND_eup_play_start(p,size,signa);
  1030.  
  1031.     while ( SND_eup_stat_flag() ) {
  1032.     MOS_rdpos(&sw,&x,&y);
  1033.     if ( sw != 0 )
  1034.         break;
  1035.     }
  1036.  
  1037.     SND_eup_play_stop();
  1038.     SND_eup_end();
  1039.     xclose(eup_buf);
  1040. }
  1041. int    JOKE_run(char *file)
  1042. {
  1043.     char    *p;
  1044.  
  1045.     if ( (p = strrchr(file,'\\')) == NULL )
  1046.     p = file;
  1047.     if ( (p = strrchr(p,'.')) == NULL )
  1048.     return FALSE;
  1049.  
  1050.     if ( strcmp(p,".TIF") == 0 )
  1051.     DSP_tiff(file);
  1052.     else if ( strcmp(p,".P16") == 0 ||
  1053.           strcmp(p,".P25") == 0 ||
  1054.           strcmp(p,".P32") == 0 )
  1055.     DSP_pxx(file);
  1056.     else if ( strcmp(p,".SND") == 0 )
  1057.     PLAY_snd(file);
  1058.     else if ( strcmp(p,".EUP") == 0 )
  1059.     PLAY_eup(file);
  1060.     else
  1061.     return FALSE;
  1062.  
  1063.     return TRUE;
  1064. }
  1065.